package com.naiterui.ehp.bs.cms.modules.recommend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.naiterui.ehp.bs.cms.common.vo.PageParamsVO;
import com.naiterui.ehp.bs.cms.common.vo.PageVO;
import com.naiterui.ehp.bs.cms.modules.recommend.entity.RecomAuditConfig;
import com.naiterui.ehp.bs.cms.modules.recommend.mapper.RecomAuditConfigMapper;
import com.naiterui.ehp.bs.cms.modules.recommend.service.IMedictionRecomAuditService;
import com.naiterui.ehp.bs.cms.modules.recommend.vo.RecomAuditConfigVO;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;

/**
 * @author guoyongxiang
 * @date 2019-06-20 14:09
 * @since 1.0.0
 */
@Service
public class MedictionRecomAuditServiceImpl extends ServiceImpl<RecomAuditConfigMapper, RecomAuditConfig> implements IMedictionRecomAuditService {

  @Override
  public PageVO<RecomAuditConfigVO> queryPage(PageParamsVO pageParamsVO) {

    RecomAuditConfig auditConfig = new RecomAuditConfig();
    QueryWrapper<RecomAuditConfig> queryWrapper = pageParamsVO.getEntityWrapper(auditConfig);
    queryWrapper.orderByDesc("id");
    IPage<RecomAuditConfig> page = this.baseMapper.selectPage(pageParamsVO.getPage(), queryWrapper);

    List<RecomAuditConfigVO> audits =
        page.getRecords()
            .stream()
            .map(a -> RecomAuditConfigVO.builder()
                .id(a.getId())
                .auditType(a.getAuditType())
                .remark(a.getRemark())
                .createdAt(a.getCreatedAt())
                .createdBy(a.getCreatedBy())
                .build())
            .collect(Collectors.toList());

    return PageVO.toPageVo(audits, page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
  }

}
